import { defineStore } from 'pinia'
const userInfoStore = defineStore('userInfo', {
	state: () => ({
		_id:'',
		nickname:'',
		username:'',
		password:'',
		telephone:'',
		createTime:0,
		token:'',
		lToken:'',
		role:'',
		permissions:[]
	}),
	actions: {
		setUserInfo(data) {
			this._id = data.userInfo._id;
			this.nickname =data.userInfo.nickname;
			this.username = data.userInfo.username;
			this.telephone = data.userInfo.telephone;
			this.createTime = data.userInfo.createTime;
			this.role = data.userInfo.role;
			this.permissions = data.permissions;
			this.token = data.token;
			this.lToken = data.lToken;
		},
		clearUserInfo() {
			this._id = '';
			this.nickname = '';
			this.username = '';
			this.telephone = '';
			this.createTime = 0;
			this.token = '';
			this.lToken = '';
		}
	},
	persist: {
		enabled: true,
		strategies: [{
			storage: localStorage,
		}],
	}

})
export default userInfoStore